From 7543cd8ce419a4d660f0ff7614f0c6e1cac81804 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Tue, 26 Jul 2016 16:00:47 -0300 Subject: [PATCH] shortcut-label: make it public GtkShortcutLabel is a widget that displays a single shortcut accelerator or gesture in the user interface, and is currently used by the shortcuts window. This widget, however, has public value as other applications also may want to expose their own shortcuts. For instance, it'll be useful for the Keyboard panel on Control Center and the new shortcut editor in Pitivi, among others. This patch exposes GtkShortcutLabel as a public widget, and adds the necessary documentation. https://bugzilla.gnome.org/show_bug.cgi?id=769205 --- docs/reference/gtk/gtk3.types.in | 1 + gtk/Makefile.am | 2 +- gtk/gtk.h | 1 + gtk/gtkshortcutlabel.c | 49 ++++++++++++++++++- ...rtcutlabelprivate.h => gtkshortcutlabel.h} | 7 ++- gtk/gtkshortcutsshortcut.c | 2 +- 6 files changed, 58 insertions(+), 4 deletions(-) rename gtk/{gtkshortcutlabelprivate.h => gtkshortcutlabel.h} (95%) diff --git a/docs/reference/gtk/gtk3.types.in b/docs/reference/gtk/gtk3.types.in index beb5a4a57a..32d57eb940 100644 --- a/docs/reference/gtk/gtk3.types.in +++ b/docs/reference/gtk/gtk3.types.in @@ -173,6 +173,7 @@ gtk_separator_get_type gtk_separator_menu_item_get_type gtk_separator_tool_item_get_type gtk_settings_get_type +gtk_shortcuts_label_get_type gtk_shortcuts_window_get_type gtk_shortcuts_section_get_type gtk_shortcuts_group_get_type diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 611b96eac0..ed6c224370 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -286,6 +286,7 @@ gtk_public_h_sources = \ gtkseparatormenuitem.h \ gtkseparatortoolitem.h \ gtksettings.h \ + gtkshortcutlabel.h \ gtkshortcutsgroup.h \ gtkshortcutssection.h \ gtkshortcutsshortcut.h \ @@ -548,7 +549,6 @@ gtk_private_h_sources = \ gtksearchentryprivate.h \ gtkselectionprivate.h \ gtksettingsprivate.h \ - gtkshortcutlabelprivate.h \ gtkshortcutswindowprivate.h \ gtkshortcutsshortcutprivate.h \ gtksidebarrowprivate.h \ diff --git a/gtk/gtk.h b/gtk/gtk.h index a7233dadd1..c818f32e97 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -187,6 +187,7 @@ #include #include #include +#include #include #include #include diff --git a/gtk/gtkshortcutlabel.c b/gtk/gtkshortcutlabel.c index 06b173662e..45cf3daca5 100644 --- a/gtk/gtkshortcutlabel.c +++ b/gtk/gtkshortcutlabel.c @@ -18,13 +18,23 @@ #include "config.h" -#include "gtkshortcutlabelprivate.h" +#include "gtkshortcutlabel.h" #include "gtklabel.h" #include "gtkframe.h" #include "gtkstylecontext.h" #include "gtkprivate.h" #include "gtkintl.h" +/** + * SECTION:gtkshortcutlabel + * @Title: GtkShortcutLabel + * @Short_description: Displays a keyboard shortcut + * @See_also: #GtkCellRendererAccel + * + * #GtkShortcutLabel is a widget that represents a single keyboard shortcut or gesture + * in the user interface. + */ + struct _GtkShortcutLabel { GtkBox parent_instance; @@ -438,6 +448,14 @@ gtk_shortcut_label_class_init (GtkShortcutLabelClass *klass) object_class->get_property = gtk_shortcut_label_get_property; object_class->set_property = gtk_shortcut_label_set_property; + /** + * GtkShortcutLabel:accelerator: + * + * The accelerator that @self displays. See #GtkShortcutsShortcut:accelerator + * for the accepted syntax. + * + * Since: 3.22 + */ properties[PROP_ACCELERATOR] = g_param_spec_string ("accelerator", P_("Accelerator"), P_("Accelerator"), NULL, @@ -452,6 +470,16 @@ gtk_shortcut_label_init (GtkShortcutLabel *self) gtk_box_set_spacing (GTK_BOX (self), 6); } +/** + * gtk_shortcut_label_new: + * @accelerator: the initial accelerator + * + * Creates a new #GtkShortcutLabel with @accelerator set. + * + * Returns: (transfer full): a newly-allocated #GtkShortcutLabel + * + * Since: 3.22 + */ GtkWidget * gtk_shortcut_label_new (const gchar *accelerator) { @@ -460,6 +488,16 @@ gtk_shortcut_label_new (const gchar *accelerator) NULL); } +/** + * gtk_shortcut_label_get_accelerator: + * @self: a #GtkShortcutLabel + * + * Retrieves the current accelerator of @self. + * + * Returns: (transfer none)(nullable): the current accelerator. + * + * Since: 3.22 + */ const gchar * gtk_shortcut_label_get_accelerator (GtkShortcutLabel *self) { @@ -468,6 +506,15 @@ gtk_shortcut_label_get_accelerator (GtkShortcutLabel *self) return self->accelerator; } +/** + * gtk_shortcut_label_set_accelerator: + * @self: a #GtkShortcutLabel + * @accelerator: the new accelerator + * + * Sets the accelerator to be displayed by @self. + * + * Since: 3.22 + */ void gtk_shortcut_label_set_accelerator (GtkShortcutLabel *self, const gchar *accelerator) diff --git a/gtk/gtkshortcutlabelprivate.h b/gtk/gtkshortcutlabel.h similarity index 95% rename from gtk/gtkshortcutlabelprivate.h rename to gtk/gtkshortcutlabel.h index 4f5096c449..aecaa78829 100644 --- a/gtk/gtkshortcutlabelprivate.h +++ b/gtk/gtkshortcutlabel.h @@ -34,11 +34,16 @@ G_BEGIN_DECLS typedef struct _GtkShortcutLabel GtkShortcutLabel; typedef struct _GtkShortcutLabelClass GtkShortcutLabelClass; - +GDK_AVAILABLE_IN_3_22 GType gtk_shortcut_label_get_type (void) G_GNUC_CONST; +GDK_AVAILABLE_IN_3_22 GtkWidget *gtk_shortcut_label_new (const gchar *accelerator); + +GDK_AVAILABLE_IN_3_22 const gchar *gtk_shortcut_label_get_accelerator (GtkShortcutLabel *self); + +GDK_AVAILABLE_IN_3_22 void gtk_shortcut_label_set_accelerator (GtkShortcutLabel *self, const gchar *accelerator); diff --git a/gtk/gtkshortcutsshortcut.c b/gtk/gtkshortcutsshortcut.c index 01df8b9aff..ca06eabcfc 100644 --- a/gtk/gtkshortcutsshortcut.c +++ b/gtk/gtkshortcutsshortcut.c @@ -20,7 +20,7 @@ #include "gtkshortcutsshortcut.h" -#include "gtkshortcutlabelprivate.h" +#include "gtkshortcutlabel.h" #include "gtkshortcutswindowprivate.h" #include "gtkprivate.h" #include "gtkintl.h" -- 2.30.2